<?php
  namespace frontend\controllers;
  use yii;
  use yii\web\Controller;
  use frontend\models\Position;
  use yii\data\Pagination;

  class PositionController extends Controller
  {
     public function actionIndex()
     {  
       $model = new Position();
        return $this->render('index', [
            'model' => $model,
        ]);

     }

     function actionCreate()
     {
        $model = new Position();
       // print_r(Yii::$app->request->post());die;
        if($model->load(Yii::$app->request->post()) && $model->validate())
        {
        	$model->save();
        	return $this->redirect(['show']);
        }
        else
        {
        	$errors = $model->errors;
            print_r($errors);
        }
     }

     function actionShow()
     {   

     	 $query = Position::find();
	    $countQuery = clone $query;
	    $pages = new Pagination(['totalCount' => $countQuery->count(),"defaultPageSize"=>4]);
	    $models = $query->offset($pages->offset)
	        ->limit($pages->limit)
	        ->all();
       // print_r($pages);die;
	    return $this->render('show', [
	         'models' => $models,
	         'pagination' => $pages,
	    ]);
     }

     function actionDel()
     {
     	$id = $_GET['id'];
     	$model = new Position();
     	$model->find()->where("id"=$id);
     	$model->delete();
     }
  }
?>